﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MaLu.Common;
using System.Xml;
using MaLu.BusiLogic;

namespace MaluJg.web.ProjectFund
{
    public partial class item1 :ProjectPage
    {
       

        protected void Page_Load(object sender, EventArgs e)
        {


            if (!IsPostBack)
            {
                string projectname =string.Empty;
                string content = BLProject.GetProjectItem(Provider, ProjectID, "item1.aspx",ref  projectname);
                if (content != string.Empty)
                {
                    XmlDocument document = new XmlDocument();
                    document.LoadXml(content);
                    XmlElement xe = document.SelectSingleNode("//项目名称") as XmlElement;
                    TextBox1.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//建设单位") as XmlElement;
                    TextBox2.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//立项批文及文号") as XmlElement;
                    TextBox3.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//立项批准机关") as XmlElement;
                    TextBox4.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//立项日期") as XmlElement;
                    TextBox5.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//建设内容") as XmlElement;
                    TextBox6.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//建筑面积") as XmlElement;
                    TextBox7.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//建设地点") as XmlElement;
                    TextBox8.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//预计开工时间") as XmlElement;
                    TextBox9.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//预计竣工时间") as XmlElement;
                    TextBox10.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//法定代表人") as XmlElement;
                    TextBox11.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//联系人及电话") as XmlElement;
                    TextBox12.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//工程类资金") as XmlElement;
                    TextBox13.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//前期费用") as XmlElement;
                    TextBox14.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//配套费用") as XmlElement;
                    TextBox15.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//合计") as XmlElement;
                    TextBox16.Text = xe.InnerText;
                    xe = document.SelectSingleNode("//备注") as XmlElement;
                    TextBox17.Text = (xe == null) ? string.Empty : xe.InnerText;
                }
                //Project p = new Project(ProjectID);
                //p.Load();
                TextBox1.Text = projectname.Replace("''", "'") ;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {

            try
            {
                if (TextBox13.Text.Trim() != string.Empty)
                {
                    double double1 = double.Parse(TextBox13.Text);
                }
                if (TextBox14.Text.Trim() != string.Empty)
                {
                    double double2 = double.Parse(TextBox14.Text);
                }
                if (TextBox15.Text.Trim() != string.Empty)
                {
                    double double3 = double.Parse(TextBox15.Text);
                }
                if (TextBox16.Text.Trim() != string.Empty)
                {
                    double double4 = double.Parse(TextBox16.Text);
                }
            }
            catch
            {
                ClientScript.RegisterStartupScript(this.GetType(), "Close", "<script>alert('部分数字格式不正确，请填写完毕后重新提交。');</script>");
                return;
            }



            BLProject.SaveProjectItem(Provider, ProjectID, "item1.aspx", FillContent());


            string msg = "已保存!";

            string script = "<script>alert('" + msg + "');</script>";
            ClientScript.RegisterStartupScript(this.GetType(), "Close", script);
        }

        private string FillContent()
        {
            string template = BLProject.GetTemplate(Provider, "item1.aspx");
            if (template != string.Empty)
            {

                XmlDocument document = new XmlDocument();
                document.LoadXml(template);
                XmlElement xe = document.SelectSingleNode("//项目名称") as XmlElement;
                xe.InnerText = TextBox1.Text;
                xe = document.SelectSingleNode("//建设单位") as XmlElement;
                xe.InnerText = TextBox2.Text;
                xe = document.SelectSingleNode("//立项批文及文号") as XmlElement;
                xe.InnerText = TextBox3.Text;
                xe = document.SelectSingleNode("//立项批准机关") as XmlElement;
                xe.InnerText = TextBox4.Text;
                xe = document.SelectSingleNode("//立项日期") as XmlElement;
                xe.InnerText = TextBox5.Text;
                xe = document.SelectSingleNode("//建设内容") as XmlElement;
                xe.InnerText = TextBox6.Text;
                xe = document.SelectSingleNode("//建筑面积") as XmlElement;
                xe.InnerText = TextBox7.Text;
                xe = document.SelectSingleNode("//建设地点") as XmlElement;
                xe.InnerText = TextBox8.Text;
                xe = document.SelectSingleNode("//预计开工时间") as XmlElement;
                xe.InnerText = TextBox9.Text;
                xe = document.SelectSingleNode("//预计竣工时间") as XmlElement;
                xe.InnerText = TextBox10.Text;
                xe = document.SelectSingleNode("//法定代表人") as XmlElement;
                xe.InnerText = TextBox11.Text;
                xe = document.SelectSingleNode("//联系人及电话") as XmlElement;
                xe.InnerText = TextBox12.Text;
                xe = document.SelectSingleNode("//工程类资金") as XmlElement;
                xe.InnerText = TextBox13.Text;
                xe = document.SelectSingleNode("//前期费用") as XmlElement;
                xe.InnerText = TextBox14.Text;
                xe = document.SelectSingleNode("//配套费用") as XmlElement;
                xe.InnerText = TextBox15.Text;
                xe = document.SelectSingleNode("//合计") as XmlElement;
                xe.InnerText = TextBox16.Text;
                xe = document.SelectSingleNode("//备注") as XmlElement;
                xe.InnerText = TextBox17.Text;
                return document.OuterXml;
            }
            else
                return string.Empty;
        }
    }
}
